#define _CRT_SECURE_NO_WARNINGS
#include"list.h"
ListNode* BuyListNode(LTDataType x)
{
	ListNode* node = (ListNode*)malloc(sizeof(ListNode));
	if (node == NULL)
	{
		perror("malloc fail");
	}
	node->next = NULL;
	node->prev = NULL;
	node->data = x;
	return node;
}
void ListPrint(ListNode* plist)
{
	assert(plist);
	assert(plist->next);
	printf("<=>head<=>");
	ListNode* cur = plist->next;
	while (cur != plist)
	{
		printf("%d<=>", cur->data);
		cur = cur->next;
	}
	printf("\n");
}
ListNode* ListCreate()
{
	ListNode* plist = BuyListNode(-1);
	plist->next = plist;
	plist->prev = plist;
	return plist;
}
void ListPushBack(ListNode* plist, LTDataType x)
{
	assert(plist);
	ListNode* newnode = BuyListNode(x);
	ListNode* tail = plist->prev;
	tail->next = newnode;
	newnode->next = plist;
	plist->prev = newnode;
	newnode->prev = tail;
}
void ListPopBack(ListNode* plist)
{
	assert(plist->next);
	ListNode* del = plist->prev;
	ListNode* tail = plist->prev->prev;
	tail->next = plist;
	plist->prev = tail;
	free(del);
	del = NULL;
}
void ListPushFront(ListNode* plist, LTDataType x)
{
	assert(plist);
	ListNode* newnode = BuyListNode(x);
	ListNode* tmp = plist->next;
	newnode->prev = plist;
	tmp->prev = newnode;
	newnode->next = tmp;
	plist->next = newnode;
}
void ListPopFront(ListNode* plist)
{
	assert(plist->next);
	ListNode* del = plist->next;
	ListNode* tmp = plist->next->next;
	plist->next = tmp;
	tmp->prev = plist;
	free(del);
	del = NULL;
}
void ListDestory(ListNode* plist)
{
	assert(plist);
	ListNode* cur = plist->next;
	while (cur != plist);
	{
		ListNode* next = cur->next;
		free(cur);
		cur = next;
	}
	free(plist);
	//plist = NULL;
}